<?php

namespace app\index\controller;

use app\common\CommonController;
use app\common\model\ToolModel;
use app\index\service\ImportexportService;
use app\index\service\DatamanufactureService;
use app\index\service\SkuAttrService;

class Datamanufacture extends CommonController
{
    public function __construct(){
        parent::__construct();
    }

    /**
     * 资料制作
     * @author LSH
     * @return json
     */
    public function getDataManufactureListedit(){
        $rules = [
            'type' => 'require'
        ];
        $this->validateData($rules);
        $data = DatamanufactureService::getDataManufactureList($this->param);
        exitJson($data);
    }

    /**
     * 资料制作导出
     * @author LSH
     * @return json
     */
    public function exportDataManufactureListedit()
    {
        $this->param['actionAsync'] = "\app\index\service\DatamanufactureService::getDataManufactureList";
        $result = ImportexportService::exportLogic($this->param, 30);
        $result['url']='/#/Queue/index';
        exitJson($result);
    }

    /**
     * 资料制作
     * @author LSH
     * @return json
     */
    public function getDataManufactureListimg(){
        $rules = [
            'type' => 'require'
        ];
        $this->validateData($rules);
        $data = DatamanufactureService::getDataManufactureList($this->param);
        exitJson($data);
    }

    /**
     * 资料制作导出
     * @author LSH
     * @return json
     */
    public function exportDataManufactureListimg()
    {
        $this->param['actionAsync'] = "\app\index\service\DatamanufactureService::getDataManufactureList";
        $result = ImportexportService::exportLogic($this->param, 31);
        $result['url']='/#/Queue/index';
        exitJson($result);
    }

    /**
     * 详情
     * @author LSH
     * @return json
     */
    public function skuDetails(){
        $rules = [
            'id' => 'require'
        ];
        $this->validateData($rules);
        $data = DatamanufactureService::getSkuInfoDetailsLogic($this->param);
        exitJson($data);
    }
    //资料制作 编辑新品 老品
    public function manufactureEdit(){
        $data=file_get_contents("php://input");
        $dataJson=json_decode($data,true);
        checkParam($dataJson,['e'],'id');
        checkParam($dataJson,['i'],'type');
        $dataJson['function']='app\index\service\SkuAttrService::manufactureEdit';
        exitJson(ToolModel::dbRollback($dataJson));
    }
    //获取描述 标题模板 速卖通模板 以及对应的值
    public function getTemplate(){
        checkParam($this->param,['e'],'id');
        exitJson(SkuAttrService::getTemplate($this->param));
    }
    //获取速卖通分类
    public function getSmtCate(){
        exitJson(SkuAttrService::getSmtCate());
    }
    //获取速卖通分类属性
    public function getSmtCateAttributeByCateId(){
        exitJson(SkuAttrService::getSmtCateAttributeByCateId($this->param));
    }
    //获取sku对应的spu 多属性
    public function getSpuAttrBySku(){
        exitJson(SkuAttrService::getSpuAttrBySku($this->param));
    }
    //资料制作-编辑-批量制作
    public function uploadManufactureEdit(){
        $param = $this->param;
        $param['actionAsync'] = "\app\index\service\SkuAttrService::uploadManufactureEdit";
        $result = ImportexportService::importTask($param, 29,2);
        exitJson($result);
    }

    /**
     * 资料制作图片列表导出
     * @author LSH
     * @return json
     */
    public function exportImgManufactureList()
    {
        $this->param['actionAsync'] = "\app\index\service\DatamanufactureService::getDataManufactureList";
        $this->param['type'] = 'img';
        $result = ImportexportService::exportLogic($this->param, 24);
        $result['url']='/#/Queue/index';
        exitJson($result);
    }

    /**
     * 制作提交状态更改
     * @author LSH
     * @return json
     */
    public function updateManufactureStatus(){
        $rules = [
            'sku' => 'require'
        ];
        $this->validateData($rules);
        $data = DatamanufactureService::updateManufactureStatusLogic($this->param);
        returnJson($data);
    }

    /**
     * 资料包导入
     * @author LSH
     * @return array
     */
    public function uploadImgSubmitInfo(){
        $param = $this->param;
        $param['actionAsync'] = "\app\index\service\DatamanufactureService::uploadImgSubmitInfo";
        $result = ImportexportService::importTask($param, 25,2);
        exitJson($result);
    }
}